/***********************************************************************
 * Module:  SysClass.java
 * Author:  LXZ
 * Purpose: Defines the Class SysClass
 ***********************************************************************/
package com.sogoodsoft.entity.app;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.sogoodsoft.entity.IdEntity;

/** 系统分类信息表 */
@Entity
@Table(name = "SYS_CLASS")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SysClass extends IdEntity {

	/** 分类名称 */
	public java.lang.String name;

	/** 编码 */
	public java.lang.String code;

	/** 值 */
	public java.lang.String value;

	/** 顺序 */
	public Long odr;

	/** 状态 */
	public java.lang.String status;

	/** 无递归时的简单分类，如果存在父类，此属性无效 */
	public java.lang.String type;

	public java.lang.String note;
	
	public java.util.List<SysClass> child;

	public SysClass parent;
	
	public Long parentId;
	
	/*功能描述和说明*/
	public String description;
	
	public java.lang.String getName() {
		return name;
	}

	public void setName(java.lang.String name) {
		this.name = name;
	}

	public java.lang.String getCode() {
		return code;
	}

	public void setCode(java.lang.String code) {
		this.code = code;
	}

	public java.lang.String getValue() {
		return value;
	}

	public void setValue(java.lang.String value) {
		this.value = value;
	}


	public Long getOdr() {
		return odr;
	}

	public void setOdr(Long odr) {
		this.odr = odr;
	}

	public java.lang.String getStatus() {
		return status;
	}

	public void setStatus(java.lang.String status) {
		this.status = status;
	}

	public java.lang.String getType() {
		return type;
	}

	public void setType(java.lang.String type) {
		this.type = type;
	}

	public java.lang.String getNote() {
		return note;
	}

	public void setNote(java.lang.String note) {
		this.note = note;
	}

	@OneToMany(mappedBy="parent",cascade=CascadeType.ALL)
	@OrderBy("odr asc")
	public java.util.List<SysClass> getChild() {
		return child;
	}

	public void setChild(java.util.List<SysClass> child) {
		this.child = child;
	}

	@ManyToOne
	@JoinColumn(name="parent_id")
	public SysClass getParent() {
		return parent;
	}

	public void setParent(SysClass parent) {
		this.parent = parent;
	}
	
	@Column(name="parent_id",insertable=false,updatable=false)
	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	/**
	 * 遍历子节点
	 * @return
	 */
	public List<SysClass> composite(){
		List<SysClass> list = new ArrayList<SysClass>();
		list.add(this);
		if(this.hasChild()){
			List<SysClass> children = this.getChild();
			for (SysClass sys : children) {
				//System.out.println(sys.getName());
				list.addAll(sys.composite());
			}
			
		}
		
		

		
		return list;
	}
	
	public boolean hasChild(){
		if(this.getChild()!=null&&this.getChild().size()!=0) return  true;
		else return false;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}